﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DelegateExample
{
    class Program
    {
        static void Main(string[] args)
        {
            BatteryLevel bat = new BatteryLevel();
            //bat.batteryLevelPusher += new BatteryLevel.BatteryLevelIndicate(BatteryLevel);
            //bat.batteryLevelPusher += delegate(int value) { Console.WriteLine("Anonim level {0}", value); };
            //bat.batteryLevelPusher += (newValue) => { Console.WriteLine("Lambda level {0}", newValue); };

            bat.CurrentBatteryLevel = 35;
            bat.CurrentBatteryLevel = 30;
            bat.CurrentBatteryLevel = 25;
            bat.CurrentBatteryLevel = 20;
            bat.CurrentBatteryLevel = 15;

            Console.Read();
        }

        public static void BatteryLevel(int newValue)
        {
            Console.WriteLine("New Battery level is : " + newValue);
        }
    }

    public class BatteryLevel
    {
        int currentBatteryLevel;

        public delegate void BatteryLevelIndicate(int value);

        public BatteryLevelIndicate batteryLevelPusher;

        public int CurrentBatteryLevel
        {
            get 
            {
                return currentBatteryLevel;
            }
            set
            {
                currentBatteryLevel = value;
                if (batteryLevelPusher != null)
                    batteryLevelPusher(currentBatteryLevel);
            }
        }
    }
}
